package ua.tyran53red.user;

import java.awt.Image;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import ua.tyran53red.banner.BannerPanel;

public class UserPanel extends JPanel {
	private static final long serialVersionUID = 1L;
	private JLabel lblIcon = null;
	private JLabel lblName = null;
	private JLabel lblStatus = null;
	private JTextArea txaUsers = new JTextArea();
	private JScrollPane jsbUsers = new JScrollPane(txaUsers);
	private BannerPanel pnlBanner = null;
	private String[] iconMas = {"google_logo.jpg", "wikipedia_logo.png", "lp_logo.png", "youtube_logo.jpg", "lp_logo.png"};
	private int[] iconWidth = {171, 123, 99, 167, 210};
	private int[] iconHeight = {100, 150, 114, 125, 163};
	
	public UserPanel(int width, int height, String userName) {
		setBounds(0, 25, width, height);
		setLayout(null);
		lblIcon = new JLabel(new ImageIcon(new ImageIcon("data/images/user.png").getImage().getScaledInstance(96, 96, Image.SCALE_DEFAULT)));
		lblIcon.setBounds(16, 16, 96, 110);
		add(lblIcon);
		lblName = new JLabel(userName);
		lblName.setBounds(120, 16, 100, 25);
		add(lblName);
		lblStatus = new JLabel("online");
		lblStatus.setBounds(120, 42, 100, 25);
		add(lblStatus);
		pnlBanner = new BannerPanel(220, height, iconMas, iconWidth, iconHeight);
		pnlBanner.setBounds(width - 220, 0, 220, height);
		add(pnlBanner);
	}

	public void setUser(String name, String status, String usersList, boolean type) {
		if (type) {
			this.removeAll();
		} else {
			remove(lblStatus);
			remove(lblIcon);
		}
		lblName.setText(name);
		
		if (type) {
			lblIcon = new JLabel(new ImageIcon(new ImageIcon("data/images/user.png").getImage().getScaledInstance(96, 96, Image.SCALE_DEFAULT)));
			lblStatus.setText(status);
			add(lblStatus);
		} else {
			lblIcon = new JLabel(new ImageIcon(new ImageIcon("data/images/channel.jpg").getImage().getScaledInstance(96, 110, Image.SCALE_DEFAULT)));
			txaUsers.setText(usersList);
			txaUsers.setEditable(false);
			jsbUsers.setBounds(220, 16, 150, 75);
			add(jsbUsers);
		}
		lblIcon.setBounds(16, 16, 96, 110);
		add(lblName);
		add(lblIcon);
		add(pnlBanner);
		this.repaint();
	}
	
	public void repaint(int width, int height) {
		pnlBanner.setBounds(width - 220, 0, 220, height);
		this.repaint();
	}
}
